fix(hooks): inject stdout into context + register missing events (#298)#299
Open
mpfaffenberger wants to merge 2 commits intomainfrom
Open
fix(hooks): inject stdout into context + register missing events (#298)#299mpfaffenberger wants to merge 2 commits intomainfrom
mpfaffenberger wants to merge 2 commits intomainfrom
Conversation
- Add VisibilityStore class for reusable visibility persistence - Add Space key to toggle model visibility (hides selected model) - Add Tab key to show/hide all (session-level filter) - Persist hidden models across sessions via JSON config - Add tests for visibility functionality - Tests preserve user's visibility config during test runs
Two closely-related fixes for the Claude Code hooks plugin:
1. Hook stdout is now propagated into the model context (exit code 0):
- SessionStart: stdout cached and appended to the system prompt via a
new load_prompt callback in the plugin.
- UserPromptSubmit: stdout prepended to the user prompt before the
model sees it, via a new 'user_prompt_submit' callback phase fired
from run_with_mcp.
- PreToolUse: stdout prepended to the tool observation by extending
the pre_tool_call return contract with {'inject_context': '...'}
in pydantic_patches.
2. UserPromptSubmit, PreCompact, SessionEnd, and Notification events
are now registered and fire:
- Added four new PhaseType entries + trigger functions in callbacks.py.
- Plugin now wires session_end/shutdown, pre_compact via
message_history_processor_start, and a notification phase.
Covered by 19 new tests in test_claude_code_hooks_issue_298.py. Full
existing test suite (1896 passed, 6 skipped) stays green.
c1f396b to
daa401a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #298.
Milton's report was spot on. Two fixes wrapped in one PR since they're tightly coupled.
What was broken
Hook stdout was captured but never injected into the agent context.
ExecutionResult.stdoutwas populated, the README promised "Exit code 0 → stdout shown in transcript", but every wired callback inplugins/claude_code_hooks/register_callbacks.pyonly checkedresult.blocked. Hooks could veto, but not inform.UserPromptSubmit,PreCompact,SessionEnd, andNotificationwere ghosts. Schema-registered, silently no-op'd at runtime.What's fixed
Stdout → model context
SessionStartload_promptcallback in the plugin. Cached once per process.UserPromptSubmituser_prompt_submitphase fired from_runtime.run_with_mcp).PreToolUsepre_tool_callreturn contract with{"inject_context": "..."};pydantic_patches.pyapplies it when the tool result is a string.Newly-wired events
PhaseTypeentries + triggers tocallbacks.py:user_prompt_submit,pre_compact,session_end,notification.session_end(andshutdownfor belt-and-braces) →SessionEndhook.message_history_processor_start→PreCompacthook.notification→Notificationhook.user_prompt_submit→UserPromptSubmithook with stdout injection + block support.Tests
tests/plugins/test_claude_code_hooks_issue_298.pycover all three injection paths and all four newly-wired events.Back-compat notes
pre_tool_callreturn contract is additive: existing{"blocked": True, ...}behavior untouched.{"inject_context": "..."}is the new optional key.Docs
hook_engine/README.mdexit-codes section expanded with a "Where stdout goes" table.🐶 Signed, Biscuit (code-puppy-de7a94). Milton, thanks for the crisp report.